﻿@using System.Globalization
@using Common
@using Models.UserModels
@model IQueryable<Plan>
@{
    DateTime date = ViewBag.date;
}

<div>
    <blockquote class="col-lg-2 pull-left">
        <h3>我的计划</h3>
    </blockquote>
    <div class="col-xs-3  pull-right">
        @Html.Partial("Search_Input")
    </div>

</div>
<div class="clearfix"></div>
<div>
    <div class="pull-right" style="width: 28%">
        <div>
            <ul class="list-inline text-center ">
                <li><a data-ajax="true" data-ajax-mode="replace" data-ajax-update="#Main" href="@Url.Action("Index", new { date = date.AddMonths(-1) })"><i class="fa fa-chevron-left"></i></a></li>
                <li><a href="javascript:;">@date.ToString("yyyy年MM月")</a></li>
                <li><a data-ajax="true" data-ajax-mode="replace" data-ajax-update="#Main" href="@Url.Action("Index", new { date = date.AddMonths(1) })"><i class="fa fa-chevron-right"></i></a></li>
                <li>
                    <a data-ajax="true" data-ajax-mode="replace" data-ajax-update="#Main" href="@Url.Action("Index", new { date = DateTime.Today })"><i class="fa fa-home"></i> @lang.ToDay</a>
                </li>
            </ul>
        </div>
        <div class="text-center">
            <ul class="nav nav-pills">
                <li style="width: 13%;">日</li>
                <li style="width: 13%;">一</li>
                <li style="width: 13%;">二</li>
                <li style="width: 13%;">三</li>
                <li style="width: 13%;">四</li>
                <li style="width: 13%;">五</li>
                <li style="width: 13%;">六</li>
                @for (var i = 1; i <= (int)DateTime.Parse(date.Year + "-" + date.Month + "-01").DayOfWeek; i++)
                {
                    <li style="width: 13%;"><a href="javascript:;"></a></li>
                }

                @{
                    var calendermodel = Model.Where(a => !a.Finish).Select(a => new { a.StartDate, a.EndDate }).ToList();
                }
                @for (var i = 1; i <= DateTime.DaysInMonth(date.Year, date.Month); i++)
                {
                    var calenderstartdate = DateTime.Parse(date.Year + "-" + date.Month + "-" + i);
                    var calenderenddate = calenderstartdate.AddDays(1);

                    <li class="@(calenderstartdate == date.Date ? "active" : "")" style="width:13%;">
                        @Ajax.ActionLink(i + (calendermodel.Any(a => !(a.EndDate <= calenderstartdate || a.StartDate >= calenderenddate)) ? "." : ""), "Index", new { date = calenderstartdate }, new AjaxOptions { UpdateTargetId = "Main" })
                    </li>
                }
            </ul>
        </div>
    </div>
    <div id="day" style="width: 70%">
        <blockquote>
            @Html.Partial("Create_Input", new Plan() { StartDate = date, EndDate = date.AddDays(1) })
        </blockquote>
        <div style="margin: 15px 0;">
            @{
                var endDate = date.AddDays(1);
            }
            @foreach (var item in Model.Where(a => !((a.EndDate <= date) || (a.StartDate >= endDate))))
            {
                <blockquote>
                    <span class="pull-right">
                        @if (item.Finish)
                        {
                            <a class="btn btn-small btn-success" data-ajax="true" data-ajax-method="Delete" data-ajax-mode="replace" data-ajax-update="#Main" href="@Url.Action("Delete", new { type = "Finish", item.Id, date = date })"><i class=" fa fa-check"></i>&nbsp;已完成</a>
                        }
                        else
                        {
                            <span>&nbsp;</span>
                            <a class="btn btn-small btn-info" data-ajax="true" data-ajax-mode="replace" data-ajax-update="#Main" href="@Url.Action("Edit", new { item.Id, date = date })"><i class=" fa fa-edit"></i>&nbsp;@lang.Edit</a>

                            <span>&nbsp;</span>
                            <a class="btn btn-small btn-danger" data-ajax="true" data-ajax-confirm="您确定要删除该记录吗？该操作不可恢复！" data-ajax-method="Delete" data-ajax-mode="replace" data-ajax-update="#Main" href="@Url.Action("Delete", new { type = "Delete", item.Id, date = date })"><i class=" fa fa-times"></i>&nbsp;@lang.Delete</a>

                            <span>&nbsp;</span>
                            <a class="btn btn-small btn-primary" data-ajax="true" data-ajax-method="Delete" data-ajax-mode="replace" data-ajax-update="#Main" href="@Url.Action("Delete", new { type = "Finish", item.Id, date = date })"><i class=" fa fa-check"></i>&nbsp;@lang.Finish</a>
                        }
                    </span>
                    @Html.Partial("PlanItem", item)
                </blockquote>
            }
        </div>
    </div>
</div>
